// 测试slice()是不是深拷贝

{
  const arr1 = [1, 2, 3, 4];
  const arr2 = arr1; //引用 浅拷贝
  const arr3 = arr1.slice(); //深拷贝
  arr1.pop();
  console.log(arr2, arr3);
}

// 自己写一个 every
Array.prototype.MyEvery = function (callbackfn) {
  "use strict";
  var T, k;
  if (this == null) {
    throw new TypeError("this is null or not defined");
  }
  var O = Object(this); //指向调用对象
  var len = O.length >>> 0; //0填充右位移
  if (typeof callbackfn !== "function") {
    throw new TypeError();
  }

  for (var k = 0; k < len; k++) {
    var kValue = O[k];
    var bool = callbackfn.call(T, kValue, k, O);
    if (!bool) {
      return false;
    }
  }

  return true;
};

const arr = [1, 2, 3, 4, 5];
arr.MyEvery((item, l, k) => {
  console.log(item, l, k);
  return item > 0;
});

//测试 values() 方法
const array1 = [1, 30, 4, 21, 100000];
const iterator = array1.values();
let val;
while ((val = iterator.next().value)) {
  console.log(val);
}
